package dev.alm.guiguxiaozhiapp.controller;

import dev.alm.guiguxiaozhiapp.agent.XiaoZhiAgent;
import dev.alm.guiguxiaozhiapp.bean.ChatForm;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("xiaozhi")
@CrossOrigin
public class XiaozhiController {

    @Resource
    private XiaoZhiAgent xiaoZhiAgent;

    @RequestMapping("chat")
    public String chat(@RequestBody ChatForm chatForm) {
        return xiaoZhiAgent.chat(chatForm.getMemoryId(), chatForm.getMessage());
    }

    @RequestMapping(value = "stream", produces = "text/stream;charset=utf-8")
    public Flux<String> stream(@RequestParam("memoryId") String memoryId, @RequestParam("message") String message) {
        return xiaoZhiAgent.stream(memoryId, message);
    }

    @PostMapping(value = "poststream", produces = "text/stream;charset=utf-8")
    public Flux<String> postStream(@RequestBody ChatForm chatForm) {
        return xiaoZhiAgent.stream(chatForm.getMemoryId(), chatForm.getMessage());
    }

}
